package cqupt.spark_log.main;

import cqupt.spark_log.contrant.Contant;
import cqupt.spark_log.fileio.FileReadMan;
import cqupt.spark_log.fileio.FileWriteMan;
/**
 * 生成空的策略表用，在实验中有一部需要将数据全部清空，生成一个空的策略表，保留表的结构
 * @author TomWang
 *
 */
public class InitTableMain {
	public static void main (String[] args) {
		Main.main(args);
		FileReadMan fileReadMan = new FileReadMan("/"+Contant.APP_NAME,true);
		//获得分区数
		String num = getNum(Contant.BASE_PATH);
		FileWriteMan fileWriteMan = new FileWriteMan(2,"/iniTable",Contant.APP_NAME+"-"+num);
		while (fileReadMan.hasNext()){
			String line = fileReadMan.next();
			if (!line.startsWith(",")) {
				StringBuilder stringBuilder = new StringBuilder(line);
				int start = stringBuilder.indexOf(",")+1;
				String str = "0;0,0;0,0;0,0;0,0;0,0;0";
				stringBuilder.replace(start, stringBuilder.length(), str);
				line = stringBuilder.toString();
			}
			fileWriteMan.insertLine(line);
		}
		System.out.println("策略表更新成功");
	}

	private static String getNum(String bASE_PATH) {
		String[] base_path_array = bASE_PATH.split("/");
		String dirName = base_path_array[base_path_array.length-2];
		String[] dirName_array = dirName.split("-");
		return dirName_array[dirName_array.length-2];
	}
}
